package com.fstech.whiteboadrd.lib.bean;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.text.TextUtils;

import com.fstech.whiteboadrd.lib.Utils.BitmapUtils;
import com.fstech.whiteboadrd.lib.view.SketchView;
import com.fstech.whiteboadrd.utils.UIUtils;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class SketchData {
    public boolean isSaved() {
        return isSaved || !TextUtils.isEmpty(imagePath);
    }

    public void setSaved(boolean saved) {
        isSaved = saved;
    }

    public List<PhotoRecord> photoRecordList;
    public List<StrokeRecord> strokeRecordList;
    public List<StrokeRecord> strokeRedoList;
    public Bitmap thumbnailBM;//缩略图文件
    public Bitmap backgroundBM;
    public int strokeType;
    public int editMode;
    public String imagePath;

    private boolean isSaved;

    public String getImagePath() {
        return imagePath;
    }

    public void setImagePath(String imagePath) {
        this.imagePath = imagePath;
    }

    private SketchData() {
        strokeRecordList = new ArrayList<>();
        photoRecordList = new ArrayList<>();
        strokeRedoList = new ArrayList<>();
        backgroundBM = null;
        thumbnailBM = null;
        strokeType = StrokeRecord.STROKE_TYPE_DRAW;
        editMode = SketchView.EDIT_STROKE;
    }

    public static SketchData newInstance(String imagePath) {
        SketchData sketchData = new SketchData();
        sketchData.setImagePath(imagePath);
        Bitmap bitmap = getSDCardPhoto(imagePath);
        sketchData.backgroundBM = bitmap;
        sketchData.thumbnailBM = bitmap;
        return sketchData;
    }

    public static SketchData newInstance() {
        SketchData sketchData = new SketchData();
        return sketchData;
    }

    public static Bitmap getSDCardPhoto(String path) {
        File file = new File(path);
        if (file.exists()) {
            return BitmapUtils.decodeSampleBitMapFromFile(UIUtils.getContext(), path, 1f);
        } else {
            return null;
        }
    }

}
